//q7a.cpp
//This program takes a roman number and print a decimal format.
//
//Binyamin 28 december 2017
//===========================================================================
#include <iostream>

using namespace std;

//1. Prompt the user for a number.
//2. Circle through the digits to calculate the number.
//3. Reviewing the input for each one.
//4. print the number.

int main()
{
	int num; //num - the output number.
	int M,D,C,L,X,V,I; // Counters for each letter.
	char c; // c - the current letter.
	bool good_input = true; // good_input - a flag for correct input.
	num = 0;
	M = 0;
	D = 0;
	C = 0;
	L = 0;
	X = 0;
	V = 0;
	I = 0;
	cout << "Please enter a romainianaina number" << endl;
	c = cin.get();
	while( c != '\n' && good_input)
	{
		switch(c)
		{
			case 'M': num += 1000;
				  M++;
				  if(D || C || L || X || V || I) good_input=false;
				  break;
			case 'D': num += 500;
				  D++;
				  if(D>=2) good_input=false;
				  if( C || L || X || V || I) good_input=false;
				  break;
			case 'C': num += 100;
				  C++;
				  if(C>=5) good_input=false;
				  if( L || X || V || I) good_input=false;
				  break;
			case 'L': num += 50;
				  L++;
				  if(L>=2) good_input=false;
				  if( X || V || I) good_input=false;
				  break;
			case 'X': num += 10;
				  X++;
				  if(X>=5) good_input=false;
				  if( V || I) good_input=false;
				  break;
			case 'V': num += 5;
				  V++;
				  if(V>=2) good_input=false;
				  if( I) good_input=false;
				  break;
			case 'I': num++;
				  I++;
				  if(I>=5) good_input=false;
				  break;
		}
		c = cin.get();
	}
	if(good_input) cout << "The number in decimal form is " << num << endl;
	else cout << "You didn't enter a good number!" << endl;
	return 0;
}
//output
//Please enter a romainianaina number MMXVI
//The number in decimal form is 2016
